<template>
	<view class="container">
		<!-- <button class="service" open-type="contact"><image src="../../static/images/service.png"></image>联系客服</button> -->
		<view class="mask" :style="{width:w,height:h}" v-show="display==1" v-on:click="close_dialog"></view>
		<view class="dialog" v-show="display==1">
			<view class="dialog_title">绑定手机号码，以便与APP账号信息同步</view>
			<button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" class="phone_button">绑定手机号码</button>
		</view>
		<view class="mask" :style="{width:w,height:h}" v-show="con_display==1" v-on:click="close_dialog"></view>
		<view class="dialog" v-show="con_display==1">
			<view class="dialog_title">马上与客户联系</view>
			<button open-type="contact" class="phone_button">点击与客服联系</button>
		</view>
		<view class="mask" :style="{width:w,height:h}" v-show="bind_display==1" v-on:click="close_dialog"></view>
		<view class="dialog" v-show="bind_display==1">
			<view class="dialog_title">输入推荐人推广码</view>
			<input class="inputtext" type="number" placeholder="请输入推广码" :value="recommend==0?'':recommend"  @input="input_"/>
			<view class="recommend" v-if="upname!=''">推荐人：{{upname}}</view>
			<view class="dialog_button">
				<view  class="c_button" v-on:click="check_member">检查推荐人</view>
				<view  class="b_button" v-on:click="bind_member">确认绑定</view>
			</view>

		</view>
		<!--#ifdef MP-WEIXIN -->
		<view class="system">
			<image :src="static_url+'/qrcode.png'" data-url="qrcode" v-on:click="operate"></image>
			<view class="code_name">推广码</view>
		</view>
		<!--#endif-->
		<view class="top">
			<view class="logo">
				<image class="avatar" :src="avatarUrl" v-if="avatarUrl.length>10"></image>
				<image class="avatar" :src="static_url+'/logo.png'" v-else></image>
			</view>
			<view class="member_info" v-if="member_id!=0">
				<view class="member_name" v-if="grade!=0">
					<view class="nickname" v-if="nickname.length>12">{{nickname.substr(0,12)}}</view>
					<view class="nickname" v-else>{{nickname}}</view>
					<view class="grade" v-if="grade==1"><image :src="static_url+'/x.png'"></image>推广会员</view>
					<view class="grade" v-if="grade==2"><image :src="static_url+'/y.png'"></image>管家</view>
					<view class="grade" v-if="grade==3"><image :src="static_url+'/y.png'"></image>管家</view>
					<view class="grade" v-if="grade==4"><image :src="static_url+'/y.png'"></image>合伙人</view>
<!--					<view class="grade" v-else><image :src="static_url+'/y.png'"></image>{{grade_name}}</view>-->
				</view>
				<view class="member_name_" v-else>
					<view class="nickname" v-if="nickname.length>12">{{nickname.substr(0,12)}}</view>
					<view class="nickname" v-else>{{nickname}}</view>
				</view>
				<view class="member_code">
					<view class="grade_code">邀请码：{{member_id}}</view>
					<view :id="member_id" class="member_copy" v-on:click="copy">复制</view>
				</view>
				<!--#ifdef MP-WEIXIN -->
				<button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" class="phone_button_" v-if="phone=='0'">绑定手机号码</button>
				<!--#endif-->
			</view>
			<!-- #ifdef MP-WEIXIN -->
			<view class="member_info" v-else>
				<button open-type="getUserInfo" v-on:click="login_submit" class='member_tag'>登录/注册</button>
			</view>
			<!-- #endif -->
			<!--#ifdef APP-PLUS-->
			<view class="member_info" v-else>
				<view  v-on:click="app_login_submit" class='member_tag'>马上登录/注册</view>
			</view>
			<!-- #endif -->
			<!--#ifdef H5 -->
			<view class="member_info" v-else>
				<view  v-on:click="h5_login_submit" class='member_tag'>马上登录/注册</view>
			</view>
			<!-- #endif -->
		</view>
		<view class="total">
<!--			<view class="total_unit" data-url="balance" v-on:click="operate">-->
<!--				<view class="total_number">{{blue_integral}}</view>-->
<!--				<view class="total_remark">&lt;!&ndash; <image :src="static_url+'/integral.png'"></image> &ndash;&gt;蓝积分</view>-->
<!--			</view>-->
			<view class="total_unit" data-url="form_withdrawal" v-on:click="operate">
				<view class="total_number">{{balance}}</view>
				<view class="total_remark"><!-- <image :src="static_url+'/price.png'"></image> -->可提现余额</view>
			</view>
			<view class="total_unit" data-url="balance">
				<view class="total_number">{{integral}}</view>
				<!-- <view class="total_number">{{red_integral}}</view> -->
				<view class="total_remark"><!-- <image :src="static_url+'/price.png'"></image> -->积分</view>
			</view>
      <view class="total_unit" data-url="form_withdrawal">
        <view class="total_number">{{welfare_price}}</view>
        <view class="total_remark"><!-- <image :src="static_url+'/price.png'"></image> -->公益金</view>
      </view>
		</view>
		<view class="warning" v-on:click="cancel_replace" v-show="replace_id!='0'">正在替会员操作，（点击我，马上取消代替操作）</view>
		<view class="menu">
			<view class="menu_title" data-url="order?status=2" v-on:click="operate">
				<view class="menu_name"><image :src="static_url+'/order.png'"></image>我的订单</view>
				<view class="more">
					全部<image src="../../static/images/more.png"></image>
				</view>
			</view>
			<view class="menu_con">
<!--				<view class="order_unit" data-url="order?status=0" v-on:click="operate">-->
<!--					<image mode="widthFix" :src="static_url+'/o1.png'"></image>-->
<!--					<view class="order_name">待付款</view>-->
<!--				</view>-->
				<view class="order_unit" data-url="order?status=1" v-on:click="operate">
					<image mode="widthFix" :src="static_url+'/o2.png'"></image>
					<view class="order_name">待发货</view>
				</view>
				<view class="order_unit" data-url="order?status=2" v-on:click="operate">
					<image mode="widthFix" :src="static_url+'/o3.png'"></image>
					<view class="order_name">待收货</view>
				</view>
				<view class="order_unit" data-url="order?status=3" v-on:click="operate">
					<image mode="widthFix" :src="static_url+'/o4.png'"></image>
					<view class="order_name">已完成</view>
				</view>
<!--				<view class="order_unit" data-url="order?status=4" v-on:click="operate">-->
<!--					<image mode="widthFix" :src="static_url+'/o5.png'"></image>-->
<!--					<view class="order_name">退款</view>-->
<!--				</view>-->
			</view>
		</view>
		<view class="menu">
			<view class="menu_unit" data-url="user_info" v-on:click="operate">
				<image mode="widthFix" :src="static_url+'/bind.png'"></image>
				<view class="menu_name">更新我的信息
				</view>
				<image class="right" src="../../static/images/more.png"></image>
			</view>
			<view class="menu_unit" data-url="bind" v-on:click="operate" v-if="upid==0">
				<image mode="widthFix" :src="static_url+'/bind.png'"></image>
				<view class="menu_name">绑定推荐人</view>
				<image class="right" src="../../static/images/more.png"></image>
			</view>
			<view class="menu_unit" data-url="merchant" v-on:click="operate" v-if="store_id==0">
				<image mode="widthFix" :src="static_url+'/store.png'"></image>
				<view class="menu_name">申请注册门店</view>
				<image class="right" src="../../static/images/more.png"></image>
			</view>
			<view class="menu_unit" data-url="merchant" v-on:click="operate" v-else>
				<image mode="widthFix" :src="static_url+'/store.png'"></image>
				<view class="menu_name">完善门店信息
					<text v-if="verify_status==0">(审核中)</text>
					<text v-if="verify_status==2">(审核不通过)</text>
				</view>
				<image class="right" src="../../static/images/more.png"></image>
			</view>
<!--			<view class="menu_unit" data-url="coupon_list" v-on:click="operate" v-if="store_id>0">-->
<!--				<image mode="widthFix" :src="static_url+'/coupon.png'"></image>-->
<!--				<view class="menu_name">卡券管理</view>-->
<!--				<image class="right" src="../../static/images/more.png"></image>-->
<!--			</view>-->
<!--			<view class="menu_unit" data-url="store_sale" v-on:click="operate" v-if="store_id>0">-->
<!--				<image mode="widthFix" :src="static_url+'/store_sale.png'"></image>-->
<!--				<view class="menu_name">门店业绩管理</view>-->
<!--				<image class="right" src="../../static/images/more.png"></image>-->
<!--			</view>-->
<!--			<view class="menu_unit" data-url="sale_info" v-on:click="operate" v-else>-->
<!--				<image mode="widthFix" :src="static_url+'/store_sale.png'"></image>-->
<!--				<view class="menu_name">业务员业绩管理</view>-->
<!--				<image class="right" src="../../static/images/more.png"></image>-->
<!--			</view>-->
			<view class="menu_unit" data-url="team" v-on:click="operate">
				<image mode="widthFix" :src="static_url+'/team.png'"></image>
				<view class="menu_name">团队管理</view>
				<image class="right" src="../../static/images/more.png"></image>
			</view>
<!--			<view class="menu_unit" data-url="replace?type=1" v-on:click="operate">-->
<!--				<image mode="widthFix" :src="static_url+'/replace.png'"></image>-->
<!--				<view class="menu_name">替Ta购买</view>-->
<!--				<image class="right" src="../../static/images/more.png"></image>-->
<!--			</view>-->
			<view class="menu_unit" data-url="commision" v-on:click="operate">
				<image mode="widthFix" :src="static_url+'/commission.png'"></image>
				<view class="menu_name">订单明细</view>
				<image class="right" src="../../static/images/more.png"></image>
			</view>
			<view class="menu_unit" data-url="order_relation" v-on:click="operate">
				<image mode="widthFix" :src="static_url+'/commission.png'"></image>
				<view class="menu_name">订单关联</view>
				<image class="right" src="../../static/images/more.png"></image>
			</view>
<!--			<view class="menu_unit" data-url="gift" v-on:click="operate">-->
<!--				<image mode="widthFix" :src="static_url+'/gift.png'"></image>-->
<!--				<view class="menu_name">领取礼品</view>-->
<!--				<image class="right" src="../../static/images/more.png"></image>-->
<!--			</view>-->
			<view class="menu_unit" data-url="address?order_id=0&goods_id=0" v-on:click="operate">
				<image mode="widthFix" :src="static_url+'/address.png'"></image>
				<view class="menu_name">收货地址</view>
				<image class="right" src="../../static/images/more.png"></image>
			</view>
			<view class="menu_unit" data-url="coupon" v-on:click="operate">
				<image mode="widthFix" :src="static_url+'/coupon.png'"></image>
				<view class="menu_name">我的卡券</view>
				<image class="right" src="../../static/images/more.png"></image>
			</view>
			<view class="menu_unit" data-url="coupon" v-if="store_id>0" v-on:click="scan">
				<image mode="widthFix" :src="static_url+'/scan.png'"></image>
				<view class="menu_name">扫码核销</view>
				<image class="right" src="../../static/images/more.png"></image>
			</view>
			<!-- <view class="menu_unit" data-url="coupon" v-on:click="scan">
				<image mode="widthFix" :src="static_url+'/scan.png'"></image>
				<view class="menu_name">测试</view>
				<image class="right" src="../../static/images/more.png"></image>
			</view> -->
			<!--#ifdef APP-PLUS -->
<!--			<view class="menu_unit" data-url="system" v-on:click="operate">-->
<!--				<image mode="widthFix" :src="static_url+'/system.png'"></image>-->
<!--				<view class="menu_name">设置</view>-->
<!--				<image class="right" src="../../static/images/more.png"></image>-->
<!--			</view>-->
<!--			<view class="service" v-on:click="contact">-->
<!--				<image mode="widthFix" :src="static_url+'/server.png'"></image>-->
<!--				<view class="menu_name">在线客服</view>-->
<!--				<image class="right" src="../../static/images/more.png"></image>-->
<!--			</view>-->
			<!--#endif-->
			<!-- #ifdef H5 -->
<!--			<view class="menu_unit" data-url="system" v-on:click="operate">-->
<!--				<image mode="widthFix" :src="static_url+'/system.png'"></image>-->
<!--				<view class="menu_name">设置</view>-->
<!--				<image class="right" src="../../static/images/more.png"></image>-->
<!--			</view>-->
<!--			<wx-open-launch-weapp id="launch-btn" username="gh_87e8741e177a" path="pages/member/index?contact=1">-->
<!--				<script type="text/wxtag-template">-->
<!--					<view style="display: flex;justify-content:flex-start;align-items: center;">-->
<!--						<img style="width:22px;height:22px;display:block" src="https://zhangjie.jdmuguzhid.com/static/images/yztang//server.png"/>-->
<!--						<view style="font-size:15px;line-height: 44px;margin-left:10px;">在线客服</view>-->
<!--					</view>-->
<!--			    </script>-->
<!--			</wx-open-launch-weapp>-->
			<!-- <view class="menu_unit" v-on:click="test_page">
				<image mode="widthFix" :src="static_url+'/system.png'"></image>
				<view class="menu_name">客服跳转</view>
				<image class="right" src="../../static/images/more.png"></image>
			</view> -->
			<!-- #endif -->
			<!--#ifdef MP-WEIXIN -->
<!--			<button class="service" v-on:click="applet" hover-class="none">-->
<!--				<image mode="widthFix" :src="static_url+'/server.png'"></image>-->
<!--				<view class="menu_name" style="width:91%">微商城</view>-->
<!--				&lt;!&ndash; <image class="right" src="../../static/images/more.png"></image> &ndash;&gt;-->
<!--			</button>-->
			<button class="service" open-type="contact" hover-class="none">
				<image mode="widthFix" :src="static_url+'/server.png'"></image>
				<view class="menu_name" style="width:91%">在线客服</view>
				<!-- <image class="right" src="../../static/images/more.png"></image> -->
			</button>
			<view class="menu_unit" v-on:click="contact_us">
				<image mode="widthFix" :src="static_url+'/server.png'"></image>
				<view class="menu_name">联系我们</view>
				<image class="right" src="../../static/images/more.png"></image>
			</view>
<!--			<view class="contact_us" v-on:click="contact_us">-->
<!--				<image mode="widthFix" :src="static_url+'/server.png'"></image>-->
<!--				<view class="menu_name">联系我们</view>-->
<!--				<image class="right" src="../../static/images/more.png"></image>-->
<!--			</view>-->
			<!--#endif-->
<!--			<view class="rule_text" v-on:click="privacy"><text >《谷牧之道用户服务协议及隐私政策》</text></view>-->
		</view>
	</view>
</template>
<style>
	.mask{position: fixed;top:0;left:0;z-index: 999;opacity: 0.6;background: #000000;}
	.dialog{width:70%;background: #FFFFFF;position: fixed;top:450upx;left:15%;padding:30upx 0;
	        border-radius: 20upx;z-index: 9991;display: flex;justify-content: center;align-items: center;flex-direction: column;}
	.dialog_title{width:94%;line-height: 50upx;font-size: 28upx;text-align: center;padding:20upx 3%}
	.inputtext{width:90%;font-size: 28upx;text-align: center;margin:20upx 3%;border:1px solid #F1F1F1;border-radius: 10upx;line-height:80upx;height:80upx;}
	.dialog_button{width:94%;padding:20upx 3%;display: flex;justify-content: space-between;align-items: center;}
	.c_button,.b_button{width: 45%;border-radius: 10upx;height: 80upx;line-height: 80upx;color: #FFFFFF;font-size: 28upx;margin:0 !important;padding:0 !important;
	            display: flex;justify-content: center;align-items: center;background-image: linear-gradient(#43eac9, #24c3a4);}
	.recommend{font-size:28upx;}			
	.warning{width:96%;margin:0 2%;background:#E03636;border-radius:20upx;height: 60upx;line-height:60upx;color: #FFFFFF;text-align:center;font-size: 28upx;}
	.menu{width:96%;margin:0 2% 10upx 2%;background: #FFFFFF;border-radius:20upx;}
	.menu_title{width:94%;padding: 10upx 3%;display: flex;justify-content: space-between;align-items: center;height:80upx;border-bottom: 1px solid #f5f5f5;}
	.menu_name{font-size:28upx;display:flex;justify-content: flex-start;align-items: center;width:85%;}
	.menu_name image{width:30upx;height: 30upx;margin-right:10upx;}
	.menu_name text{padding-left:20upx;color: #E03636;}
	.more{font-size:28upx;display:flex;justify-content: flex-end;align-items: center;}
	.more image{width:30upx;height: 30upx;margin-left:10upx;}
	.menu_con{width:94%;padding: 10upx 3%;display: flex;justify-content: space-between;align-items: center;height: 120upx;}
	.order_unit{width: 18%;flex-direction: column;display: flex;justify-content: center;align-items: center;}
	.order_unit image{width:65upx;}
	.order_name{width:100%;text-align:center;line-height:50upx;font-size:26upx;}
	
	.menu_unit{width: 94%;padding: 10upx 3%;display: flex;justify-content: space-between;align-items: center;height: 80upx;border-bottom: 1px solid #f5f5f5;}
	.menu_unit image,.service image{width:40upx;}
	.right{width:30upx !important;height:30upx;}
	/* .menu_unit:last-child{border:0} */
	.service{width: 94%;padding: 10upx 3% !important;margin:0 !important;display: flex;justify-content: space-between;align-items: center;height: 80upx;background: #FFFFFF;}
	.service::after{border:0;}
	#launch-btn{width: 94%;padding: 10upx 3%;margin:0;height: 80upx;background: #FFFFFF;display: flex;}
	/*******************************/
	.total{width:94%;margin:10upx 3%;border-radius: 20upx 20upx 0 0;background-image: linear-gradient(#4de8da, #a6efe6);background-image: url("https://zhangjie.jdmuguzhid.com/static/images/yztang/bg.png");
	display: flex;justify-content: center;align-items: center;height: 150upx;background-repeat: no-repeat;background-size: 100% auto;}
	.total_unit{width:30%;}
	.total_number{font-size:48upx;color:#FFFFFF;font-weight: bold;width:100%;text-align: center;}
	.total_remark{font-size:24upx;display: flex;justify-content: center;align-items: center;color: #ffffff;}
	.total_remark image{width:30upx;height: 30upx;margin-right: 10upx;}
	
	/*******************************/
	page,.container{width:100%;background:#F4F4F4;}
	.top{width:90%;padding:20upx 3% 60upx 7%;display: flex;justify-content: flex-start;align-items: center;background: #F4F4F4;}
	.logo{width:150upx;height: 150upx;border-radius: 75upx;overflow: hidden;background: #FFFFFF;}
	.avatar{width:150upx;height: 150upx;}
	.member_tag{width: 60%;border-radius: 10upx;height: 80upx;line-height: 80upx;color: #333333;font-size: 28upx;margin:0 !important;padding:0 !important;
	            display: flex;justify-content: center;align-items: center;background: #F4F4F4;/* background-image: linear-gradient(#43eac9, #24c3a4); */}
	.member_tag:after{border:0;color: #FFFFFF;}
	.member_info{margin-left: 20upx;width:60%;display: flex;justify-content: center;align-items: flex-start;flex-direction: column;}
	
	.member_name{width:100%;display: flex;justify-content: space-between;align-items: flex-start;flex-direction: column;height:100upx;}
	.member_name_{width:100%;line-height: 20upx;/* height:100upx; */}
	.nickname{font-size:28upx;}
	.grade{padding:8upx 20upx;display:flex;justify-content: flex-start;align-items: center;text-align: center;height: 30upx;line-height:30upx;;border-radius: 20upx;background: #e8c99c;font-size:24upx;}
	.grade image{width:25upx;height:25upx;}
	.system{width: 80upx;height:100upx;position:absolute;right:15upx;top:15upx;flex-direction: column;display: flex;justify-content: flex-start;align-items: center;}
	.system image{width:50upx;height: 50upx;}
	.code_name{font-size: 24upx;}
	.member_code{width:100%;display: flex;justify-content: flex-start;align-items: center;margin-top:20upx;}
	.grade_code{font-size:24upx;color: #333333;}
	.member_copy{margin-left:10upx;padding:0 20upx;font-size:24upx;color:#999;border:1px solid #999;height: 30upx;line-height:30upx;border-radius: 20upx;}
	.phone_button{width: 80%;border-radius: 10upx;height: 80upx;line-height: 80upx;color: #FFFFFF;font-size: 28upx;margin:0 !important;padding:0 !important;
	            display: flex;justify-content: center;align-items: center;background-image: linear-gradient(#43eac9, #24c3a4);}
	.phone_button_{width: 80%;border-radius: 10upx;height: 60upx;line-height: 60upx;color: #FFFFFF;font-size: 28upx;
					margin-top:10upx !important;margin-right:0 !important;margin-left:0 !important;padding:0 !important;
	            display: flex;justify-content: center;align-items: center;background-image: linear-gradient(#43eac9, #24c3a4);}
	.rule_text{width:100%;line-height: 80upx;text-align: center;color: #999999;font-size: 28upx;}
	/*******************************/
	.lh{height: 100upx;width: 100%;}
	.foot{width:98%;padding:10upx 1%;background: #FFFFFF;height: 90upx;display: flex;
		  justify-content: space-between;align-items: center;position: fixed;bottom: 0;left:0;}
	.foot_unit{width:20%;display: flex;flex-direction: column;justify-content:space-between;
	           align-items: center;height: 80upx;}
	.foot_unit image{width:40upx;height: 40upx;}
	.add{width:80upx;display: flex;justify-content: center;align-items: center;height: 80upx;}
	.add image{width:80upx;height: 80upx;}
	.foot_unit_name{font-size: 24upx;color: #b5b5b5;}
	.foot_current{color: #3de9c7 !important;}
	/**********************************************/
</style>
<script>
	//#ifdef H5
	import wxjs   from '../../jweixin/lib/index.js';
	//#endif
	import toMpWeixin from '../../js_sdk/wzc-toMpWeixin/toMpWeixin.js';
	export default {
		data() {
			return {
				member_id:0,
				store_id:0,
				avatarUrl:'',
				grade:0,
				integral:0,
				blue_integral:0,
				red_integral:0,
				balance:0,
        welfare_price:0,
				contribution:0,
				nickname:'',
				grade_name:'',
				phone:'0',
				result:{},
				refresh_status:0,
				display:0,
				con_display:0,
				bind_display:0,
				recommend:0,
				upid:0,
				up_status:0,
				replace_id:'0',
				upname:'',
				w:'',
				h:'',
				verify_status:0,
				url: getApp().globalData.url,
				static_url:getApp().globalData.static
			}
		},
		onLoad(e) {
			var res = uni.getSystemInfoSync();
			var w = res.windowWidth;
			this.w = w+"px";
			this.h = res.windowHeight+"px";
			if(e.contact=="1")
			{
				this.con_display = 1;
			}

		},
		onShow()
		{
			var member_id = uni.getStorageSync("member_id");
			var replace_id = uni.getStorageSync("replace_id");

			if(replace_id!="")
			{
				this.replace_id = replace_id;
			}
			if(member_id!="")
			{
				this.initialize();

			}
		},
		onPullDownRefresh() {
			// var member_id = uni.getStorageSync("member_id");
			console.log("onPullDownRefresh");
			this.refresh_status = 1;
			this.initialize();
		},
		//#ifdef H5
		created() {
			this.share_server();
		},
		//#endif
		methods: {
			cancel_replace:function()
			{
				var that = this;
				uni.showModal({
					title:"操作提示",
					content:"取消替会员购买",
					success: (res) => {
						if(res.confirm)
						{
							uni.removeStorageSync("replace_id");
							that.replace_id = '0';
							uni.showToast({
								title:"操作成功",
								duration:1500
							})
						}
					}
				})
			},
			test_page:function()
			{
				uni.navigateTo({
					url:"test_page"
				})
			},
			input_:function(e)
			{
				this.recommend = parseInt(e.detail.value);
			},
			check_member:function()
			{
				var that = this;
				// var number  = /^\d{6,7}$/;
				// if(this.recommend.length<6 || !number.test(this.recommend))
				// {
				// 	uni.showToast({
				// 		title:'邀请码不正确',
				// 	})
				// 	return;
				// }
				// else
				// {
					uni.request({
						url: this.url+"/wechat_member_info",
						data: {member_id:this.recommend,upid:this.upid},
						header: {
						  'Content-Type': 'application/json'
						},
						success: function (res)
						{
							that.upname  = res.data.nickname;
							that.up_status  = 1;
							console.log(that.up_status);
						}
					})
				// }

			},
			bind_member:function()
			{
				var that = this;
				// var number  = /^\d$/;
				// if(this.recommend.length<6 || !number.test(this.recommend))
				// if(this.recommend.length<6)
				// {
				// 	uni.showToast({
				// 		title:'邀请码不正确',
				// 		duration:1500
				// 	})
				// 	return;
				// }
				// else
        if (this.up_status==0)
				{
					uni.showToast({
						title:'请先检查推荐人',
						duration:1500
					})
					return;
				}
				else
				{
					var member_id = uni.getStorageSync("member_id");
					that.bind_display = 0;
					uni.showModal({
						title:"绑定操作",
						content:"确认要绑定推荐人："+this.upname+"?",
						success: (res) => {
							if(res.confirm)
							{
								uni.request({
									url: this.url+"/wechat_remedy_binding_relationship",
									data: {member_id:member_id,upid:that.recommend},
									header: {
									  'Content-Type': 'application/json'
									},
									success: function (ress)
									{
										if(ress.data.status==1)
										{
											that.upname       = "";
											that.recommend    = 0;
											that.up_status    = 0;
											uni.showToast({
												title:"绑定成功",
												duration:1500
											})
											setTimeout(function(){that.initialize()},1500);
										}
										else
										{
											uni.showModal({
												title:"操作提示",
												content:ress.data.msg,
												showCancel:false
											})
										}
									}
								})
							}
						}
					})

				}
			},
			share_server:function()
			{
				var that  = this;
				var site  = window.location.href;
				uni.request({
					url: this.url+"/wechat_share",
					data: {url:site},
					header: {'Content-Type': 'application/json'},
					success: function (res)
					{
						console.log(res.data);
						wxjs.config({
						  debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
						  appId: res.data.appId,         // 必填，公众号的唯一标识
						  timestamp: res.data.timestamp, // 必填，生成签名的时间戳
						  nonceStr: res.data.nonceStr,   // 必填，生成签名的随机串
						  signature: res.data.signature,        // 必填，签名
						  jsApiList: ['wx-open-launch-weapp'],// 必填，需要使用的JS接口列表
						  openTagList:['wx-open-launch-weapp']
						});
						wxjs.ready(function (res) {
							console.log(res);
						})
						wxjs.error(function(res){
							console.log(res);
						})
					}
				})
			},
			h5_login_submit:function()
			{
				//#ifdef H5
				var ua = navigator.userAgent.toLocaleLowerCase();
				var that = this;
				if(ua.match(/MicroMessenger/i) == 'micromessenger')
				{
				   var appid = 'wxb7a354cd32681d5d';
				   var redirect_uri = encodeURIComponent(that.url+'/wap/#/pages/member/login');
				   window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize"+"?appid="+appid+"&redirect_uri="+redirect_uri+"&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect";
				}
				else
				{
					uni.navigateTo({
						url:"login"
					})
				}

				//#endif
			},
			privacy:function()
			{
				uni.navigateTo({
					url:"privacy"
				})
			},
			close_dialog:function()
			{
				this.con_display = 0;
				this.display = 0;
				this.bind_display = 0;
			},
			contact:function()
			{
				toMpWeixin({
					appId:'wxb7a354cd32681d5d',
					gid:'gh_87e8741e177a',
					path:'pages/member/index?contact=1'
				})
			},
			scan:function()
			{
				var that = this;
				uni.scanCode({success: function (res) {console.log(res.result); that.qrcode_writeoff(res.result);}});
			},
			qrcode_writeoff:function(data)
			{
				var tmp = data.split("||");
				var that = this;
				var member_id = uni.getStorageSync("member_id");
				uni.showModal({
					title:"核销确认",
					content:"确认要核销该优惠券？",
					success: (r) => {
						if(r.confirm)
						{
							uni.request({
								url: that.url+'/wechat_write_off_coupons',
								data: {get_coupon_id:tmp[0],consumer:tmp[1],member_id:member_id},
								header: {'Content-Type': 'application/json'},
								success: (res) => {
									if(res.data.status==1)
									{
										uni.showToast({
											title:"核销成功",
											duration:3000
										})
									}
									else
									{
										var msg = res.data.err_msg;
										uni.showToast({
											title:msg,
											duration:2000,
											icon:"none"
										})
									}
								}
							});
						}
					}
				})
			},
			app_login_submit:function()
			{
				uni.navigateTo({
					url:"login"
				})
			},
			copy:function(e)
			{
				var data = e.currentTarget.id;
				uni.setClipboardData({data:data});
				uni.showToast({
					title:"复制成功",
					duration:1000
				})
			},
			test:function()
			{
				uni.scanCode({
					success: function (res) {
							var tmp = res.path.split("=");
							var member_id = tmp[1];
							uni.setStorageSync("upid",member_id);
						},
				});
			},
			operate:function(e)
			{
				var phone = uni.getStorageSync("phone");
				if(phone.length>0)
				{
					var url = e.currentTarget.dataset.url;
					if(url=="gift")
					{
						if(this.grade!=2)
						{
							uni.showModal({
								title:"权限提示",
								content:"您还不是顾问，\r\n请解锁顾问权限，进行0元礼品领取",
								showCancel:false
							})
							return;
						}
					}
					// if(url=="coupon")
					// {
					// 	uni.showModal({
					// 		title:"操作提示",
					// 		content:"暂未开放，敬请期待",
					// 		showCancel:false
					// 	})
					// 	return;
					// }
					if(url=="bind")
					{
						this.bind_display = 1;
						return;
					}
					uni.navigateTo({
						url:url
					})
				}
				else
				{
					uni.showToast({
						title:"请先登录",
						duration:1500
					})
				}
			},
			contact_us:function() {
				uni.showModal({
					title:"操作提示",
					content:'电话：18525061788',
					showCancel:false
				})
			},
      applet:function () {
        uni.navigateToMiniProgram({
          // appid  写你要跳转的小程序的 appid
          appId: 'wxe5eda38a29bfb140',
          // 路径写  src下的路径,假如你跳转的是pages下的页面,就可以写pages/index
          path: '',
          extraData: {
            // 'type': 'out'
          },
          // 这个不写的话会显示开发环境,不能正常跳转,写上就能正常跳转了
          envVersion: 'develop',
          success(res) {
            // 打开成功
            uni.showToast({
              title: '跳转成功'
            })
          },
          fail(err) {
            // 打开失败/取消
            uni.showToast({
              title: '系统错误'
            })
          }
        })
      },
			initialize:function()
			{
				var that = this;
				var member_id = uni.getStorageSync("member_id");
				var upid      = uni.getStorageSync("upid");
				if(upid=="undefined" || upid=="")
				{
					upid = 0;
				}
				// console.log("初始化UPID："+upid);
				// var member_id = 169378;
				uni.request({
					url: this.url+"/wechat_member_info",
					data: {member_id:member_id,upid:upid},
					header: {
					  'Content-Type': 'application/json'
					},
					success: function (res)
					{
					  console.log(res.data.welfare_price);
						uni.setStorageSync("member_id",res.data.member_id);
						uni.setStorageSync("avatarUrl",res.data.img);
						uni.setStorageSync("nickname",res.data.nickname);
						uni.setStorageSync("grade",res.data.grade);
						uni.setStorageSync("integral",res.data.integral);
						uni.setStorageSync("blue_integral",res.data.blue_integral);
						uni.setStorageSync("red_integral",res.data.red_integral);
						uni.setStorageSync("phone",res.data.phone);
						uni.setStorageSync("balance",res.data.balance);
						uni.setStorageSync("welfare_price",res.data.welfare_price);
						uni.setStorageSync("upid",res.data.upid);
						uni.setStorageSync("store_id",res.data.result[0].store_id);
						that.store_id  = res.data.result[0].store_id;
						that.avatarUrl = res.data.img;
						that.member_id = res.data.member_id;
						that.nickname  = res.data.nickname;
						that.grade       = res.data.grade;
						that.grade_name  = res.data.grade_name;
						that.integral    = res.data.integral;
						that.blue_integral    = res.data.blue_integral;
						that.red_integral    = res.data.red_integral;
						that.phone       = res.data.phone;
						that.balance     = res.data.balance;
						that.welfare_price     = res.data.welfare_price;
						that.result      = res.data.result[0];
						that.upid        = res.data.upid;
						that.verify_status = res.data.store_verify_status;
						if(res.data.contribution>=0)
						{
							that.contribution = res.data.contribution;
						}
						if(that.refresh_status==1)
						{
							that.refresh_status = 0;
							uni.stopPullDownRefresh();
						}
					}
				})
			},
			login_submit:function()
			{
				var upid = uni.getStorageSync("upid");
				var member_id = uni.getStorageSync("member_id");
				if(member_id=="")
				{
					member_id = 0;
				}
				if(upid=="undefined")
				{
					upid = 0;
				}

				var code = '';
				var that = this;
				var useinfo = {};

				uni.getUserProfile({
					lang: 'zh_CN',
					desc:'获取用户展示信息',
					success: function (e)
					{
						useinfo = e.userInfo;
						uni.login({
						    success: function (res)
							{
								code = res.code;
								uni.request({
									url: that.url+"/wechat_get_openid",
									data: {
										provider:'weixin',
										member_id:member_id,
										code: code,
										nickname: useinfo.nickName,
										gender: useinfo.gender,
										avatarUrl: useinfo.avatarUrl,
										upid:upid
									},
									header: {
									  'Content-Type': 'application/json'
									},
									success: function (res)
									{
										uni.setStorageSync("member_id",res.data.member_id);
										uni.setStorageSync("avatarUrl",res.data.img);
										uni.setStorageSync("nickname",res.data.nickname);
										uni.setStorageSync("grade",res.data.grade);
										uni.setStorageSync("integral",res.data.integral);
										uni.setStorageSync("blue_integral",res.data.blue_integral);
										uni.setStorageSync("red_integral",res.data.red_integral);
										uni.setStorageSync("phone",res.data.phone);
										uni.setStorageSync("balance",res.data.balance);
										uni.setStorageSync("welfare_price",res.data.welfare_price);
										uni.setStorageSync("upid",res.data.upid);
										that.avatarUrl   = res.data.img;
										that.member_id   = res.data.member_id;
										that.nickname    = res.data.nickname;
										that.grade       = res.data.grade;
										that.grade_name  = res.data.grade_name;
										that.integral    = res.data.integral;
										that.phone       = res.data.phone;
										that.balance     = res.data.balance;
										that.welfare_price     = res.data.welfare_price;
										that.upid        = res.data.upid;
										that.verify_status = res.data.store_verify_status;
										if(res.data.phone=='0')
										{
											that.display = 1;
										}
									}
								})
						    }
						})
					},
					fail:function(e)
					{
						console.log(e);
					}
				});

			},
			getPhoneNumber:function(e)
			{
				// console.log(e);
				var that = this;
				uni.getProvider({
					service: 'oauth',
					success: function (res) {
						if (~res.provider.indexOf('weixin')) {
							uni.login({
								provider: 'weixin',
								success: function (loginRes) {
									that.code = loginRes.code;
									that.get_key_session(loginRes.code,e);
								}
							});
						}
					}
				});
			},
			get_key_session:function(code,e)
			{
				var that = this;
				var member_id = uni.getStorageSync("member_id");
				uni.request({
					url:this.url+'/wechat_get_session',
					data: {code:code,member_id:member_id},
					header: {'Content-Type': 'application/json'},
					success: (res) => {
						that.get_user_phone(e.detail.iv,res.data.session_key,e.detail.encryptedData);
					}
				})
			},
			get_user_phone(iv,key,encryptedData)
			{
				var member_id = uni.getStorageSync("member_id");
				var that = this;
				uni.request({
					url:this.url+'/wechat_get_user_phone',
					method:'POST',
					data: {"iv":encodeURI(iv),
					      "session_key":encodeURI(key),
						  "encryptedData":encodeURI(encryptedData),member_id:member_id},
					header: {'Content-Type': 'application/x-www-form-urlencoded'},
					success: (res) => {
						if(res.data.status==1)
						{
							that.phone = res.data.phone;
							uni.setStorageSync("phone",res.data.phone);
							that.display = 0;
							that.initialize();
						}
						else if(res.data.status==0)
						{
							uni.showToast({
								title:'授权失败',
								duration:5000
							})
						}
						else
						{
							uni.setStorageSync("member_id",res.data.member_id);
							that.initialize();
						}
					}
				})
			}
		}
	}

</script>